import { postData, deleteData, getData } from '@/utils/request';

/**
 * 获取角色列表
 * @param data
 * @returns
 */
export async function getList(data: RoleAPI.ConditionQuery) {
  const result = await postData(`/role/list`, data);
  return result;
}

/** 新增
 * @param data
 * @returns
 */
export async function create(data: RoleAPI.DataType) {
  const result = await postData(`/role/add`, data);
  return result;
}

/**
 * 更新
 * @param data
 * @returns
 */
export async function update(data: RoleAPI.DataType) {
  const result = await postData(`/role/update`, data);
  return result;
}

/**
 * 删除
 * @param data
 * @returns
 */
export async function del(data: string) {
  const result = await deleteData(`/role/delete/${data}`);
  return result;
}

/**
 * 获取权限列表
 */
export async function menuList() {
  const result = await getData(`/permission/permissions/1`);
  return result;
}

/**
 * 为角色分配权限
 * @param data
 * @returns
 */
export async function doAssign(data: RoleAPI.DataType) {
  const result = await postData(`/role/distribute`, data);
  return result;
}

/**
 * 根据角色id获取权限
 * @param data
 * @returns
 */
export async function getAssign(data: string) {
  const result = await getData(`/permission/getByRoleId/${data}`);
  return result;
}
